//
//  ByCellOrderPayType.m
//  itboye_shop_ios
//
//  Created by pro on 17/2/10.
//  Copyright © 2017年 com.itboye. All rights reserved.
//

#import "ByCellOrderPayType.h"

@implementation ByCellOrderPayType
{
    UIImageView *_iconView;             // 图片
    UILabel     *_titleLabel;           // 标题
    UILabel     *_subTitleLabel;        // 子标题
    UIButton    *_selectBtn;            // 选中视图
    UILabel     *_line;                 // 线条
    
}

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        
        self.selectionStyle = UITableViewCellSelectionStyleNone;
        [self setupUI];
    }
    return self;
}

- (void)setupUI {
    
    // 主图
    _iconView = [[UIImageView alloc] init];
    //_iconView.backgroundColor = [UIColor orangeColor];
    [self.contentView addSubview:_iconView];
    
    // 标题
    _titleLabel = [[UILabel alloc] init];
    _titleLabel.numberOfLines = 2;
    _titleLabel.font = FONT(16);
    _titleLabel.textColor = TEXT_COLOR;
    _titleLabel.textAlignment = NSTextAlignmentLeft;
    [self.contentView addSubview:_titleLabel];
    
    // 子标题
    _subTitleLabel = [[UILabel alloc] init];
    _subTitleLabel.adjustsFontSizeToFitWidth = YES;
    _subTitleLabel.font = FONT(12);
    _subTitleLabel.textColor = [UIColor grayColor];
    _subTitleLabel.textAlignment = NSTextAlignmentLeft;
    [self.contentView addSubview:_subTitleLabel];
    
    // 选中视图
    _selectBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    [_selectBtn setImage:[UIImage imageNamed:@"Common_unSelected"] forState:UIControlStateNormal];
    [_selectBtn setImage:[UIImage imageNamed:@"Common_selected"] forState:UIControlStateSelected];
    [self.contentView addSubview:_selectBtn];
    _selectBtn.userInteractionEnabled = NO;
    
    // 线
    _line = [[UILabel alloc] init];
    _line.backgroundColor = ZJ_SEPLINE_COLOR;
    [self.contentView addSubview:_line];
}

- (void)setInfoDic:(NSDictionary *)infoDic {
    
    _infoDic = infoDic;
    
    [self setNeedsLayout];
}

- (void)setSelect:(BOOL)select {
    
    _select = select;
    _selectBtn.selected = _select;
}

- (void)layoutSubviews {
    
    [super layoutSubviews];
    
    _iconView.frame     = CGRectMake(0, 0, 30, 30);
    _iconView.left      = 10;
    _iconView.y         = self.height / 2;
    
    _selectBtn.frame    = CGRectMake(0, 0, 20, 20);
    _selectBtn.right    = self.width - 15;
    _selectBtn.y        = self.height / 2;
    
    _titleLabel.frame   = CGRectMake(_iconView.right + 10, 0, _selectBtn.left - 10 - (_iconView.right + 10), 18);
    _subTitleLabel.frame= CGRectMake(_titleLabel.left, 0, _titleLabel.width, 14);
    
    CGFloat margin      = 4;
    CGFloat remine      = (self.height - _titleLabel.height - _subTitleLabel.height - margin) / 2;
    _titleLabel.top     = remine;
    _subTitleLabel.top  = _titleLabel.bottom + margin;
    
    _line.frame         = CGRectMake(0, 0, self.width, 0.5);
    _line.bottom        = self.height;
    
    // 设置数据
    _titleLabel.text    = _infoDic[@"title"];
    _subTitleLabel.text = _infoDic[@"subTitle"];
    _iconView.image = [UIImage imageNamed:_infoDic[@"icon"]];
    
}


@end
